package cn.kuporo.seckill.activity.controller;

import cn.kuporo.seckill.activity.domain.model.vo.ActivitySaveReqVO;
import cn.kuporo.seckill.activity.application.service.SeckillActivityService;
import cn.kuporo.seckill.activity.domain.model.SeckillActivity;
import cn.kuporo.seckill.activity.domain.model.vo.ActivityUpdateStatusReqVO;
import cn.kuporo.seckill.common.model.dto.SeckillActivityDTO;
import cn.kuporo.seckill.common.model.response.Response;
import cn.kuporo.seckill.common.model.vo.*;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: kuporo
 * @since: 2025/7/7
 * @description:
 */
@RestController
@RequestMapping(value = "/activity")
@RequiredArgsConstructor
public class SeckillActivityController {
    private final SeckillActivityService seckillActivityService;
    /**
     * 保存秒杀活动
     */
    @PostMapping("/save")
    public Response<?> saveSeckillActivity(@RequestBody @Validated ActivitySaveReqVO activitySaveReqVO){
        return seckillActivityService.saveSeckillActivity(activitySaveReqVO);
    }

    /**
     * 根据状态获取活动列表
     */
    @PostMapping("/listByStatus")
    public Response<List<SeckillActivity>> getSeckillActivityList(@RequestBody @Validated FindActivityByStatusReqVO findActivityByStatusReqVO){
        return Response.success(seckillActivityService.getSeckillActivityList(findActivityByStatusReqVO.getStatus()));
    }

    /**
     * 获取秒杀活动列表
     */
    @PostMapping("/listByStatusAndVersion")
    public Response<List<FindActivityBySARspVO>> getSeckillActivityList(@RequestBody @Validated FindActivityBySAReqVO findActivityBySAReqVO){
        return Response.success(seckillActivityService.getSeckillActivityList(findActivityBySAReqVO.getStatus(), findActivityBySAReqVO.getVersion()));
    }

    /**
     * 根据id获取秒杀活动详情
     */
    @GetMapping("/getSeckillActivityById")
    public Response<SeckillActivityDTO> getSeckillActivityById(@RequestParam("id") Long id,
                                                               @RequestParam(value = "version",required = false) Long version){
        return Response.success(seckillActivityService.getSeckillActivityById(id, version));
    }

    /**
     * 根据时间和状态获取活动列表
     */
    @PostMapping(value = "/listByStatusAndTime")
    public Response<List<SeckillActivity>> getSeckillActivityListBetweenStartTimeAndEndTime(@RequestBody @Validated FindActivityByTimeAndStatusReqVO findActivityByTimeAndStatusReqVO){
        return Response.success(seckillActivityService.getSeckillActivityListBetweenStartTimeAndEndTime(findActivityByTimeAndStatusReqVO.getCurrentTime(), findActivityByTimeAndStatusReqVO.getStatus()));
    }

    /**
     * 获取id获取秒杀活动详情
     */
    @PostMapping("/getById")
    public Response<SeckillActivity> getSeckillActivityById(@RequestBody @Validated FindActivityByIdReqVO findActivityByIdReqVO){
        return Response.success(seckillActivityService.getSeckillActivityById(findActivityByIdReqVO.getId()));
    }

    /**
     * 更新活动状态
     */
    @PostMapping("/updateStatus")
    public Response<?> updateStatus(@RequestBody @Validated ActivityUpdateStatusReqVO activityUpdateStatusReqVO){
        return seckillActivityService.updateStatus(activityUpdateStatusReqVO.getId(), activityUpdateStatusReqVO.getStatus());
    }
}
